package test;
import   javax.swing.*;   
import   javax.swing.border.Border;   
import   javax.swing.border.EmptyBorder;   
import   javax.swing.tree.DefaultTreeModel;   
import   javax.swing.tree.DefaultMutableTreeNode;   
import   javax.swing.tree.DefaultTreeCellRenderer;   
import   java.awt.*;   
  
public   class   TreeImage   extends   JFrame   {   
        DefaultTreeModel   model;   
        JTree   tree;   
  
        public   TreeImage()   {   
                super("");   
                setSize(300,   200);   
                model   =   createModel();   
                tree   =   new   JTree(model);   
                tree.setCellRenderer(new   MyTree());   
                JScrollPane   jsp   =   new   JScrollPane(tree);   
                getContentPane().add(jsp,   BorderLayout.CENTER);   
                setVisible(true);   
        }   
  
        public   DefaultTreeModel   createModel()   {   
                DefaultMutableTreeNode   root   =   new   DefaultMutableTreeNode("a");   
                DefaultMutableTreeNode   b   =   new   DefaultMutableTreeNode("b");   
                DefaultMutableTreeNode   c   =   new   DefaultMutableTreeNode("c");   
                root.add(b);   
                root.add(c);   
                return   new   DefaultTreeModel(root);   
        }   
  
        public   static   void   main(String   args[])   {   
                TreeImage   ti   =   new   TreeImage();   
        }   
}   
  
//class   MyTree   extends   DefaultTreeCellRenderer   {   
//        Border   border   =   new   EmptyBorder(1,   1,   1,   1);   
//  
//        public   MyTree()   {   
//                setOpaque(true);   
//                setBorder(border);   
//        }   
//        
//        public   Component   getTreeCellRendererComponent(JTree   tree,   Object   value,   
//								                              boolean   sel,   
//								                              boolean   expanded,   
//								                              boolean   leaf,   
//								                              int   row,   
//								                              boolean   hasFocus)  
//        {   
//                super.getTreeCellRendererComponent(tree,value,sel,expanded,leaf,row,hasFocus);   
//  
//                setText(value.toString());   
//                if   (sel)   
//                        setForeground(getTextSelectionColor());   
//                else   
//                        setForeground(getTextNonSelectionColor());   
//                DefaultMutableTreeNode   node   =   (DefaultMutableTreeNode)   value;   
//                String   str   =   value.toString();   
//                if   (str   ==   "a")   {   
//                        this.setIcon(new   ImageIcon("message.gif"));   
//                }   
//                if   (str   ==   "b")   {   
//                        this.setIcon(new   ImageIcon("hu.gif"));   
//                }   
//                if   (str   ==   "c")   {   
//                        this.setIcon(new   ImageIcon("hou.gif"));   
//                }   
//                return   this;   
//        }   
//}   
  
